/**
 * 
 */
package br.idez.idezJet.control.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 * @author Moacir Junior
 *
 */
@FacesValidator("senhaValidador")
public class SenhaValidador implements Validator {

	@Override
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {

		UIViewRoot viewRoot = context.getViewRoot();
		UIComponent uiComponent = viewRoot.findComponent("form:inputSenha1");

		if (((UIInput) uiComponent).getValue() == null
				|| !((String) ((UIInput) uiComponent).getValue())
						.equals((String) value)) {
			FacesMessage message = new FacesMessage(
					"senha.desigual");
			message.setSeverity(FacesMessage.SEVERITY_ERROR);
			throw new ValidatorException(message);
		}

	}

}
